package cn.lr.demo;

class one{
	
}
public class ReverseStr {
	public String reverseString(String s) {
		char[] strings = s.toCharArray();
		StringBuffer str = new StringBuffer();
		for(int i=strings.length-1;i>=0;i--){
			if(strings[i] != '\n'){
				str.append(strings[i]);
			}
		}
		return str.toString();
    }
	public static void main(String[] args) {
		String str = "hello";
		/*File f = new File("D:\\str.txt");
		FileInputStream in;
		try {
			in = new FileInputStream(f);
			byte[] bt = new byte[2048];
			int len;
			while((len = in.read(bt))!=-1){
				byte[] tbt = new byte[len];
				System.arraycopy(bt, 0, tbt, 0, len);
				str += new String(tbt);
			}
			in.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		ReverseStr re = new ReverseStr();
		str = re.reverseString(str);
		System.err.println(str);
		int a = re.addDigits(1);
		System.err.println(a);
	}
	public int addDigits(int num) {
        String str = String.valueOf(num);
        int a =num;
        while(str.length()>1){
        	a=0;
        	char[] strings = str.toCharArray();
        	for(int i=0;i<strings.length;i++){
        		String s = ""+strings[i];
        		a = a+Integer.valueOf(s);
        	}
        	str = String.valueOf(a);
        }
        
        return a;
    }

}
